package com.jshcbd.modules.asset.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jshcbd.modules.asset.entity.InventoryEntity;
import com.jshcbd.modules.asset.vo.InventoryVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author zhoucd
 * @date
 * @description
 */
public interface InventoryMapper extends BaseMapper<InventoryEntity> {


    @Update("UPDATE INVENTORY SET STATE = 3 WHERE ID = #{id}")
    void updateInventoryEnd(String id);

    @Update("UPDATE ASSET A SET A.USE_STATE = B.USER_ID," +
            "A.LOCATION_BUILDING = B.LOCATION_BUILDING," +
            "A.LOCATION_FLOOR = B.LOCATION_FLOOR," +
            "A.ROOM_NAME = B.ROOM_NAME " +
            "FROM (SELECT INVENTORY_ITEM.*," +
            "           ADDRESS.LOCATION_BUILDING,ADDRESS.LOCATION_FLOOR,ADDRESS.LOCATION_FLOOR " +
            "      FROM INVENTORY_ITEM" +
            "      LEFT JOIN ADDRESS ON INVENTORY_ITEM.ADDRESS_ID = ADDRESS.ID " +
            "WHERE MAIN_ID = #{mainId}) B " +
            "WHERE A.ID = B.ASSET_ID ")
    void updateAssetByInventory(String mainId);


    @Select("SELECT A.*,B.NAME SCOPE_COMPANY_NAME FROM INVENTORY A LEFT JOIN COMPANY B ON A.SCOPE_COMPANY_ID = B.ID ${ew.customSqlSegment} ")
    IPage<InventoryVo> queryPageView(Page<InventoryVo> page, @Param(Constants.WRAPPER) QueryWrapper queryWrapper);


}
